            //////////////////////////////////////////////////////////////////
            
            function MockFacade (key)
            {
                Facade.call(this, key);    
            };
            
            /** @override */
            MockFacade.getInstance= function (key)
            {
                var appFacade= Facade.instanceMap[key];
                if (appFacade)
                {
                    return appFacade;
                };
                
                return Facade.instanceMap[key]= new MockFacade(key);
            };
            
            MockFacade.ADD_TWO= "addTwo";
            
            // extend MockFacade by Facade
            FacadeIntermediary= function () {};
            FacadeIntermediary.prototype= Facade.prototype;
            MockFacade.prototype= new FacadeIntermediary();
            
            MockFacade.prototype.initFacade= false;
            MockFacade.prototype.initNotifier= false;
            MockFacade.prototype.initView= false;
            MockFacade.prototype.initModel= false;
            MockFacade.prototype.initController= false;
            
            /** @override */
            MockFacade.prototype.initializeFacade= function ()
            {
                this.initFacade= true;
                Facade.prototype.initializeFacade.call(this);
            };
            
            /** @override */
            MockFacade.prototype.initializeModel= function ()
            {
                this.initModel= true;
                Facade.prototype.initializeModel.call(this);
            };
            
            /** @override */
            MockFacade.prototype.initializeView= function ()
            {
                this.initView= true;
                Facade.prototype.initializeView.call(this);
            };
            
            /** @override */
            MockFacade.prototype.initializeController= function ()
            {
                this.initController= true;
                Facade.prototype.initializeController.call(this);
            };
            
            /**
             * @override
             */
            MockFacade.prototype.initializeNotifier= function (key)
            {
                this.initNotifier= true;
                Facade.prototype.initializeNotifier.call(this, key);
            };
            
            /**
             * @return {Model}
             */
            MockFacade.prototype.getModel= function ()
            {
                return this.model;
            };
            
            /**
             * @return {View}
             */
            MockFacade.prototype.getView= function ()
            {
                return this.view;
            };
            
            /**
             * @return {Controller}
             */
            MockFacade.prototype.getController= function ()
            {
                return this.controller;    
            };
            
            /**
             * @return {string}
             */
            MockFacade.prototype.getMultitonKey= function ()
            {
                return this.multitonKey;
            };
            
            //////////////////////////////////////////////////////////////////
            
            AddTwoCommand.prototype= new SimpleCommand();
            AddTwoCommand.prototype.constructor= AddTwoCommand;
            
            /** @override */
            AddTwoCommand.prototype.execute= function (note)
            {
            	console.dir(note);
                var body= note.getBody();
                if ('number' !== typeof body.value)
                {
                    throw new TypeError("Number value expected by AddTwoCommand.exeucte");
                    
                }
                
                body.value= body.value+2; 
            };
            
            /**
             * @extends {SimpleCommand}
             * @implements {ICommand}
             */
            function AddTwoCommand () { };
            
            ////////////////////////////////////////////////////////////////// 
            
            MediatorIntermediary.prototype= Mediator.prototype;
            function MediatorIntermediary () { };
            MockMediator.prototype= new MediatorIntermediary();
            MockMediator.prototype.constructor= MockMediator;
            
            /**
             * @type {Array.<string>}
             * @private
             */
            MockMediator.prototype.interests=
            [
                MockFacade.ADD_TWO
            ];
            
            /** @override */
            MockMediator.prototype.listNotificationInterests= function ()
            {
                return this.interests;
            };
            
            /** @override */
            MockMediator.prototype.handleNotification= function (note)
            {
            	console.info(this.name + " handled notification " + note.getName());
                this.note= note;    
            };
            
            MockMediator.prototype.onRegister= function ()
            {
                this.registered= true;
            };
            
            MockMediator.prototype.onRemove= function ()
            {
                this.removed= true;
            };
            
            MockMediator.prototype.initializeNotifier= function (key)
            {
                this.initialized= true;
                Notifier.prototype.initializeNotifier.call(this, key);    
            };
            
            MockMediator.NAME= "MockMediator";
            
            /**
             * @extends {Mediator}
             */
            function MockMediator () {
                this.note= null;
                this.registered= false;
                this.removed= false;  
                this.initialized= false;  
                Mediator.call(this);
            };
            

            
            //////////////////////////////////////////////////////////////////
          
            function testFacadeRetrievalAndInstantiation ()
            {
                var firstKey= "A"
                ,   firstInstance= MockFacade.getInstance(firstKey)
                ,   firstAlias= Facade.getInstance(firstKey)
                ,   model
                ,   view
                ,   controller
                ,   key
                
                
                if (false === firstInstance instanceof Facade)
                    throw new Error("firstInstance should be an instance of Facade");
                
                if (false === firstInstance instanceof MockFacade)
                    throw new Error("firstInstance should be an instance of MockFacade");
                
                if (firstInstance !== firstAlias)
                    throw new Error ("Multiton retrieval error!")
                    
                if (firstInstance.getMultitonKey() !== firstKey)
                    throw new Error ("Multiton key assignment error");
                        
                if (true !== firstInstance.initFacade)
                    throw new Error("MockFacade.initializeFacade should have been invoked");
                    
                if (true !== firstInstance.initNotifier)
                    throw new Error("MockFacade.initializeNotifier should have been invoked");
                    
                if (true !== firstInstance.initView)
                    throw new Error("MockFacade.initializeView should have been invoked");
                    
                if (true !== firstInstance.initController)
                    throw new Error("MockFacade.initializeController should have been invoked");
                    
                if (true !== firstInstance.initModel)
                    throw new Error("MockFacade.initializeModel should have been invoked");
                  
                model=firstInstance.getModel();    
                view= firstInstance.getView();
                controller=firstInstance.getController();
                
                if (null == model || false === model instanceof Model)
                    throw new Error("The facades model was not instantiated");  
                    
                if (model !== Model.getInstance(firstKey))
                    throw new Error("The appFacades model can be retrieved by Model");
                
                if (null == view || false === view instanceof View)
                    throw new Error("The facades view was not instantiated");   
                    
                if (view !== View.getInstance(firstKey))
                    throw new Error ("The facades view can be retireved via View"); 
                    
                if (null == controller || false === controller instanceof Controller)
                    throw new Error("The facades constroller was not instantiated");    
                    
                if (controller !== Controller.getInstance(firstKey))
                    throw new Error ("The facades controller can be retireved via Controller");   
                    
                
                var error= null
                ,   directInstance 
                try 
                {
                    directInstance= new MockFacade("2");
                }
                catch (thrown)
                {
                    error= thrown;
                }
                
                if (null !== error)
                    throw new Error("Its possible, but ill advised to instantiate Facades directly");
                    
                    
                error= null;
                
                if (directInstance !== MockFacade.getInstance("2"))
                    throw new Error("The directly instantiated instance should have been added to the multiton map");
                
                try
                {
                    new MockFacade("2");
                }
                catch (thrown)
                {
                    error= thrown;
                }
                
                if (null === error)
                    throw new Error("It should not be possible to instantiate a Facade directly with an existing key");
                    
                if (error.message !== Facade.MULTITON_MSG)
                    throw new Error("An instantiation error should have been thrown");
                    
                if (void(0) !== MockFacade.getInstance().multitonKey)
                    throw new Error("Its ill advised, but facades can be retrieved without keys, in which case its key is undefined");
                
            };
          
            

            
            
            
            function testCommandRegistrationWithFacade ()
            {
            
                var multitonKey= "testCommandRegistrationInstance"
                ,   appFacade= MockFacade.getInstance(multitonKey)
                ,   noteName= MockFacade.ADD_TWO
                ,   noteBody=
                    {
                        value: 2
                    }
                ,   noteType=  'instruction'
                ,   notification= new Notification(noteName, noteBody, noteType)
                ,   mediator= new MockMediator();


                if (noteName !== notification.getName())
                    throw new Error ("The notification name should have been " + noteName);
                    
                if (noteType !== notification.getType())
                    throw new Error ("The notification type should have been " + noteType);
                    
                if (noteBody !== notification.getBody())
                    throw new Error ("The notification body should have been set correctly");

                // appFacade.registerMediator(mediator);
                appFacade.registerCommand(MockFacade.ADD_TWO, AddTwoCommand);
                
                if (true !== appFacade.hasCommand(MockFacade.ADD_TWO))
                    throw new Error("The add two command should have been added");
                
                
                appFacade.sendNotification(notification.getName(), notification.getBody());
            
                
                if (4 !== noteBody.value)
                    throw new Error("AddTwoCommand should have added 2 to the notification body value");
                    
                    
                appFacade.notifyObservers(notification);
                
                if (6 !== noteBody.value)
                    throw new Error("AddTwoCommand should have added 2 to the notification body value, bringing it to 6");
                    
                
                if (false !== mediator.initialized)
                    throw new Error("The mediator should not have been initialized yet");    
                
                    
                appFacade.registerMediator(mediator);
                
                if (true !== mediator.initialized)
                    throw new Error("The mediator should have been initialized after registration");
                
                if (true !== appFacade.hasMediator(MockMediator.NAME))
                    throw new Error("The mediator should have been registered with the Facade");
                
                if (true !== mediator.registered)
                    throw new Error ("The mediator should have been registered with the appFacade");
                
               	appFacade.sendNotification(notification.getName(), notification.getBody(), notification.getType());
                // appFacade.notifyObservers(notification);
                
                // debugger;
                
                if (notification != mediator.note)
                    throw new Error ("The mediator should have been notified about " + notification);
                    
                    
                var newNote= new Notification(noteName, noteBody, noteType);
                
                appFacade.removeMediator(mediator);
                
                
                
                if (true !== mediator.removed)
                    throw new Error ("The mediator should have been removed");
                    
                
                appFacade.notifyObservers(newNote);
                
                if (notification !== mediator.note)
                    throw new Error ("The mediator should not have been notified after removal");
                    
                        
                //console.log(mediator.note + '');    
                
            };
            
          
          

          
            try
            {
                testFacadeRetrievalAndInstantiation();
                testCommandRegistrationWithFacade();
                console.log("tests passed");
            }  
            catch (thrown)
            {
                console.log(thrown.stack);
            }
            
            
            